package com.foryou.wechat.controller;

import com.foryou.wechat.service.ChatService;
import com.foryou.wechat.utils.HttpContextUtils;
import com.foryou.wechat.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/chat")
public class ChatController {

    private final ChatService chatService;

    public ChatController(ChatService chatService) {
        this.chatService = chatService;
    }

    @GetMapping("/getChatList")
    public Response getChatList(@RequestParam(defaultValue = "0") int start) {
        return chatService.getChatList(HttpContextUtils.getUserId(), start);
    }

    @GetMapping("/getDetail")
    public Response getDetail(Long userId) {
        return chatService.openChatWindow(userId);
    }

    @GetMapping("/sendTextMessage")
    public Response sendTextMessage(Long chatId, String content) {
        return chatService.sendTextMessage(chatId, content);
    }

    @GetMapping("/onlineOrOffline")
    public Response onlineOrOffline(Long chatId) {
        return chatService.onlineOrOffline(HttpContextUtils.getUserId(), chatId);
    }

    @PostMapping("/sendAudioMessage")
    public Response sendAudioMessage(Long chatId,String duration,MultipartFile file) {
        return chatService.sendAudioMessage(chatId,duration,file);
    }

    @PostMapping("/sendImageMessage")
    public Response sendImageMessage(Long chatId, MultipartFile file) {
        return chatService.sendImageMessage(chatId, file);
    }

    @GetMapping("/removeList")
    public Response removeList(Long chatId) {
        return chatService.removeList(chatId, HttpContextUtils.getUserId());
    }

}
